//
//  ViewController1.m
//  BarCodeAndQRCode
//
//  Created by jiezsoft.com on 14-10-10.
//  Copyright (c) 2014年 jiezsoft.com. All rights reserved.
//

#import "saoyisaoViewController.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "HAODEsingleton.h"
#import "RDVTabBarController.h"
#import "huiyuanDetailsViewController.h"
//#import "GetProductDetailViewController.h"
//#import "kucunViewController.h"
//#import "SeriesViewController.h"
//#import "wuxiaoViewController.h"
//#import "huiyuanDetailsViewController.h"
@interface saoyisaoViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>
@property(nonatomic,strong)NSString* str;
@end

@implementation saoyisaoViewController
{
    HAODEsingleton* commdity;
    double d;
    int d1;
    UIButton*buyBtn2;
    UIButton* xiadan;
    UITextField*searchTextField;
    NSMutableArray* arrrs1;
    NSMutableArray* arrrs2;
    NSMutableArray* arrrs3;
    NSMutableArray* arrrs4;
    NSMutableArray* arrrs5;
    NSMutableArray* arrrs6;
    NSMutableArray* arrrs7;
    NSMutableArray* scanStockResultArray;
    NSMutableArray* itemUrlArray;
    NSMutableArray* itemTypeNameArray;
    NSMutableArray* itemSeriesNameArray;
    NSMutableArray* itemInDateArray;
    NSMutableArray* itemWeightArray;
    NSMutableArray* itemPriceArray;
    NSMutableArray* itemWhereArray;
    NSMutableArray* itemNameArray;
    NSMutableArray* itemCodeArray;
    
    UIButton*SCANSTOCK;
    UIButton *SCANSTOCK1;
    UIButton *shuSCANSTOCK1;
    BOOL no;
    UIButton*sxBtn;
    UIButton*huiyuan;
}
@synthesize alt = alt;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    self.navigationItem.rightBarButtonItem = nil;
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setImage:backImage forState:UIControlStateNormal];
    backButton.imageEdgeInsets = UIEdgeInsetsMake(0,0, 0, 0);
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    //    self.navigationController.delegate = self;
    
    commdity=[HAODEsingleton shared];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self add];
    
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    self.navigationController.navigationBarHidden=NO;
    
    
    
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    
    
}


-(void)add{
    [timer invalidate];
    
    UIBarButtonItem* barbuttonitem=[[UIBarButtonItem alloc]init];
    barbuttonitem.title=@"";
    barbuttonitem.tintColor=[UIColor whiteColor];
    [barbuttonitem setTintColor:[UIColor whiteColor]];
    self.navigationItem.backBarButtonItem=barbuttonitem;
    
    isDown=NO;
    num=0;
    _captureSession=nil;
    
    
    _viewPreview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    _viewPreview.frame = CGRectMake(0, 0,ScreenWidth,ScreenHeight);
    [self.view addSubview:_viewPreview ];
    [self startRead1];
    UILabel* tishi=[[UILabel alloc]initWithFrame:CGRectMake(0, ScreenHeight*380/1334,ScreenWidth,14)];
    tishi.text=@"请将二维码置于扫描取景框内";
    tishi.textColor=[UIColor whiteColor];
    tishi.textAlignment=NSTextAlignmentCenter;
    tishi.font=[UIFont systemFontOfSize:14];
    [self.view addSubview:tishi];
    
    
    UIView* view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight*440/1334)];
    view1.backgroundColor=[UIColor blackColor];
    view1.alpha=0.6;
    [_viewPreview addSubview:view1];
    UIView* view2=[[UIView alloc]initWithFrame:CGRectMake(ScreenWidth*705/750, ScreenHeight*440/1334, ScreenWidth, ScreenHeight)];
    view2.backgroundColor=[UIColor blackColor];
    view2.alpha=0.6;
    [_viewPreview addSubview:view2];
    UIView* view3=[[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight*440/1334, ScreenWidth*45/750, ScreenHeight)];
    view3.backgroundColor=[UIColor blackColor];
    view3.alpha=0.6;
    [_viewPreview addSubview:view3];
    UIView* view4=[[UIView alloc]initWithFrame:CGRectMake(ScreenWidth*45/750,ScreenHeight*900/1334, ScreenWidth*660/750, ScreenHeight)];
    view4.backgroundColor=[UIColor blackColor];
    view4.alpha=0.6;
    [_viewPreview addSubview:view4];
    
    
    _viewPreview1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"saoyisao(1).png"]];
    _viewPreview1.frame = CGRectMake(ScreenWidth*45/750, ScreenHeight*440/1334,ScreenWidth*705/750,ScreenHeight*430/1334);
    [_viewPreview addSubview:_viewPreview1];
    
    [_line removeFromSuperview];
    _line = [[UIView alloc] initWithFrame:CGRectMake(ScreenWidth*30/750, 0, ScreenWidth*600/750, 2)];
    _line.backgroundColor=luseColor;
    [_viewPreview1 addSubview:_line];
    
    
    
    d1=ScreenWidth*460/750;
    NSLog(@"ddddd%d",d1);
    if (d1==253) {
        d1=252;
    }
    if (d1==203) {
        d1=300;
    }
    NSLog(@"ddddd%d",d1);
    
    
    
    
    
    
    
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*25/750,ScreenHeight*420/1334, ScreenWidth*65/750, 1)];
    line1.backgroundColor = luseColor;
    [self.view addSubview:line1];
    
    UILabel *line11 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*25/750,ScreenHeight*420/1334,1,ScreenWidth*65/750)];
    line11.backgroundColor = luseColor;
    [self.view addSubview:line11];
    
    UILabel *line111 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*25/750,ScreenHeight*850/1334, 1,ScreenWidth*65/750)];
    line111.backgroundColor = luseColor;
    [self.view addSubview:line111];
    UILabel *line1111 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*25/750,ScreenHeight*915/1334, ScreenWidth*65/750, 1)];
    line1111.backgroundColor = luseColor;
    [self.view addSubview:line1111];
    
    UILabel *line12 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*655/750,ScreenHeight*420/1334, ScreenWidth*65/750, 1)];
    line12.backgroundColor = luseColor;
    [self.view addSubview:line12];
    UILabel *line13 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*720/750,ScreenHeight*420/1334, 1, ScreenWidth*65/750)];
    line13.backgroundColor = luseColor;
    [self.view addSubview:line13];
    
    UILabel *line112 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*655/750,ScreenHeight*915/1334, ScreenWidth*65/750,1)];
    line112.backgroundColor = luseColor;
    [self.view addSubview:line112];
    UILabel *line113 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*720/750,ScreenHeight*850/1334, 1, ScreenWidth*65/750)];
    line113.backgroundColor = luseColor;
    [self.view addSubview:line113];
    
    
    sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-35, 60*ScreenWidth/1334, ScreenWidth*60/750, ScreenWidth*60/750)];
    [sxBtn setBackgroundImage:[UIImage imageNamed:@"shanguangdeng_normal"] forState:UIControlStateNormal];
    sxBtn.imageEdgeInsets = UIEdgeInsetsMake(0,5, 0, 0);
    [sxBtn addTarget:self action:@selector(sou) forControlEvents:UIControlEventTouchUpInside];
    sxBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    UIBarButtonItem* leftBarButtonItem1 = [[UIBarButtonItem alloc] initWithCustomView:sxBtn];
    self.navigationItem.rightBarButtonItem = leftBarButtonItem1;
    
    
    timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(lineAnimation) userInfo:nil repeats:YES];
    
    
//    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth*555/750, 65*ScreenHeight/1334)];
//    view.backgroundColor=zuiqianhuicolor;
//    view.backgroundColor=[UIColor colorWithRed:222/255.0 green:222/255.0 blue:222/255.0 alpha:1];
//    view.alpha=0.69;
//    UIButton *sxBtn1 = [[UIButton alloc] initWithFrame:CGRectMake( 2, 6*ScreenHeight/1334, 50*ScreenWidth/750, 50*ScreenWidth/750)];
//    [sxBtn1 setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
//    //   [sxBtn1 addTarget:self action:@selector(sou) forControlEvents:UIControlEventTouchUpInside];
//    [view addSubview:sxBtn1];
//    self.navigationItem.titleView = view;
//    self.navigationItem.titleView.alpha=0.7;
    
   
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    searchTextField.inputAccessoryView = myToolBar;
    
    
    // Do any additional setup after loading the view from its nib.
}
-(void)OnTapDone{
    
    [searchTextField resignFirstResponder];
    //    if ([commdity.sat isEqualToString:@"HUIyuan"]) {
    ////        commdity.UstyCode=searchTextField.text;
    ////        huiyuanDetailsViewController*detailViewController = [[huiyuanDetailsViewController alloc] init];
    ////        [self.navigationController pushViewController:detailViewController animated:YES];
    //    }
    //    if ([commdity.sat isEqualToString:@"SCANSHOP"]) {
    ////        commdity.ItemCode=searchTextField.text;
    ////        danpinxiangqingViewController*detailViewController = [[danpinxiangqingViewController alloc] init];
    ////        [self.navigationController pushViewController:detailViewController animated:YES];
    //    }
    //    if ([commdity.sat isEqualToString:@"SCANSTOCK"]) {
    //
    //        if (![scanStockResultArray containsObject:searchTextField.text]) {
    //
    //            stringValue = searchTextField.text;
    //
    //             [self performSelectorOnMainThread:@selector(loadStockVC) withObject:nil waitUntilDone:NO];
    //        }else{
    //
    //
    //        }
    //
    //    }
    //
    
    
    
}

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}
-(void)sou{
    
    
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (![device hasTorch]) {
        NSLog(@"no torch");
    }else{
        [device lockForConfiguration:nil];
        no=!no;
        if (no) {
            [device setTorchMode: AVCaptureTorchModeOn];
            
            [sxBtn setBackgroundImage:[UIImage imageNamed:@"shanguangdeng_hight"] forState:UIControlStateNormal];
            
        }
        else
        {
            [device setTorchMode: AVCaptureTorchModeOff];
            [sxBtn setBackgroundImage:[UIImage imageNamed:@"shanguangdeng_normal"] forState:UIControlStateNormal];
        }
        
        
        [device unlockForConfiguration];
    }
    
    
}

-(void)huiyuan:(UIButton*)sender{
    [huiyuan setBackgroundImage:[UIImage imageNamed:@"saohuiyuan_hight"] forState:UIControlStateNormal];
    [xiadan setBackgroundImage:[UIImage imageNamed:@"saoshangpin_normal"] forState:UIControlStateNormal];
    [buyBtn2 setBackgroundImage:[UIImage imageNamed:@"saogouwu_normal"] forState:UIControlStateNormal];
    [SCANSTOCK removeFromSuperview];
    [SCANSTOCK1 removeFromSuperview];
    [shuSCANSTOCK1 removeFromSuperview];
    commdity.sat=@"HUIyuan";
    
}
-(void)xiadan:(UIButton*)sender{
    [SCANSTOCK removeFromSuperview];
    [SCANSTOCK1 removeFromSuperview];
    [shuSCANSTOCK1 removeFromSuperview];
    
    [huiyuan setBackgroundImage:[UIImage imageNamed:@"saohuiyuan_normal"] forState:UIControlStateNormal];
    [xiadan setBackgroundImage:[UIImage imageNamed:@"saoshangpin_hight"] forState:UIControlStateNormal];
    [buyBtn2 setBackgroundImage:[UIImage imageNamed:@"saogouwu_normal"] forState:UIControlStateNormal];
    commdity.sat=@"SCANSHOP";
}
-(void)buyBtn2:(UIButton*)sender{
    
    
    [self showAlertMessage:@"未开通！"];
    //    [huiyuan setImage:[UIImage imageNamed:@"saohuiyuan_normal"] forState:UIControlStateNormal];
    //    [xiadan setImage:[UIImage imageNamed:@"saoshangpin_normal"] forState:UIControlStateNormal];
    //    [buyBtn2 setImage:[UIImage imageNamed:@"saogouwu_hight"] forState:UIControlStateNormal];
    //    commdity.sat=@"SCANSTOCK";
    //
    //
    //
    //
    //    SCANSTOCK = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*290/750, ScreenHeight*980/1334, ScreenWidth* 160/750, ScreenWidth* 160/750)];
    //    SCANSTOCK.layer.masksToBounds = YES;
    //    SCANSTOCK.layer.cornerRadius = ScreenWidth* 160/750/2;
    //    SCANSTOCK.layer.borderColor = [UIColor grayColor].CGColor;
    //    SCANSTOCK.layer.borderWidth = 0.5;
    //    SCANSTOCK.contentMode = UIViewContentModeScaleAspectFit;
    //
    //    SCANSTOCK1 =[[UIButton alloc]initWithFrame:CGRectMake(290*ScreenWidth/750, ScreenHeight*1000/1334,ScreenWidth* 160/750, ScreenWidth* 160/750)];
    //    [SCANSTOCK1  setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    //    SCANSTOCK1.titleLabel.font = [UIFont systemFontOfSize:contenfot];
    //    [SCANSTOCK1 setTitle:@"扫描记录" forState:UIControlStateNormal];
    //    SCANSTOCK1.titleLabel.textAlignment = NSTextAlignmentCenter;
    //
    //    shuSCANSTOCK1 =[[UIButton alloc]initWithFrame:CGRectMake(290*ScreenWidth/750, ScreenHeight*950/1334,ScreenWidth* 160/750, ScreenWidth* 160/750)];
    //    [shuSCANSTOCK1  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    shuSCANSTOCK1.titleLabel.font = [UIFont systemFontOfSize:etwentyOReighteenth];
    //    shuSCANSTOCK1.titleLabel.textAlignment = NSTextAlignmentCenter;
    //
    //
    //    [shuSCANSTOCK1 addTarget:self action:@selector(scanStockCountBtnClick) forControlEvents:UIControlEventTouchUpInside];
    //    [shuSCANSTOCK1 setTitle: [NSString stringWithFormat:@"%ld", scanStockResultArray.count] forState:UIControlStateNormal];
    //    [self.view addSubview:SCANSTOCK];
    //     [self.view addSubview:SCANSTOCK1];
    //     [self.view addSubview:shuSCANSTOCK1];
}


-(void)lineAnimation
{
    
    
    if (isDown==NO) {
        num++;
        _line.frame=CGRectMake(ScreenWidth*30/750, 2*num, ScreenWidth*600/750, 1);
        if (2*num==d1) {
            isDown=YES;
        }
    }
    else
    {
        
        
        num--;
        _line.frame=CGRectMake(ScreenWidth*30/750, 2*num, ScreenWidth*600/750, 1);
        if (num==0) {
            isDown=NO;
        }
    }
    
}

-(BOOL)startRead1
{
    NSError *error;
    //    [_outputsetRectOfInterest:CGRectMake((124)/ScreenHigh,((ScreenWidth-220)/2)/ScreenWidth,220/ScreenHigh,220/ScreenWidth)];
    AVCaptureDevice *captureDevice=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput *input=[AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
    if (!input) {
        NSLog(@"%@", [error localizedDescription]);
        return NO;
    }
    _captureSession = [[AVCaptureSession alloc] init];
    if ([_captureSession canAddInput:input]) {
        [_captureSession addInput:input];
    }
    
    
    AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
    if ([_captureSession canAddOutput:captureMetadataOutput]) {
        [_captureSession addOutput:captureMetadataOutput];
    }
    
    
    dispatch_queue_t dispatchQueue;
    dispatchQueue = dispatch_queue_create("myQueue", NULL);
    [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
    captureMetadataOutput.metadataObjectTypes =@[AVMetadataObjectTypeQRCode];
    
    [captureMetadataOutput setRectOfInterest:CGRectMake((ScreenWidth*0.475)/ScreenHeight,((ScreenWidth-ScreenHeight*0.475)/2)/ScreenWidth,ScreenHeight*0.475/ScreenHeight,ScreenHeight*0.400/ScreenWidth)];
    
    _videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
    [_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [_videoPreviewLayer setFrame:CGRectMake(0, 0,ScreenWidth,ScreenHeight)];
    [_viewPreview.layer addSublayer:_videoPreviewLayer];
    [_captureSession startRunning];
    return YES;
}





-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
    
    if (metadataObjects != nil && [metadataObjects count] > 0) {
        AVMetadataMachineReadableCodeObject * metadataObject = [metadataObjects objectAtIndex:0];
        stringValue = metadataObject.stringValue;
        
        if ([commdity.sat isEqualToString:@"SCANSHOP"]) {
            [self performSelectorOnMainThread:@selector(loadShopVC) withObject:nil waitUntilDone:NO];
            [_captureSession stopRunning];
            //[_videoPreviewLayer removeFromSuperlayer];
            _captureSession = nil;
            [timer invalidate];
            timer=nil;
            
            
        }
        
        
        if ([commdity.sat isEqualToString:@"HUIyuan"]) {
            
            
            [self performSelectorOnMainThread:@selector(HUIyuan) withObject:nil waitUntilDone:NO];
            [_captureSession stopRunning];
            //[_videoPreviewLayer removeFromSuperlayer];
            _captureSession = nil;
            [timer invalidate];
            timer=nil;
            
        }
        
    }
    
}
-(void)HUIyuan
{
    
    
    
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    
    
    [param setValue:stringValue forKey:@"memberId"];
    
    
    NSLog(@"====%@",param);
    
    
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Business/Member/Detail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"33333333====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                commdity.Phone=[severDataDict.dataDict objectForKey:@"phone"];
                commdity.memberId=[severDataDict.dataDict objectForKey:@"memberId"];
                commdity.userName=[severDataDict.dataDict objectForKey:@"userName"];
                commdity.Sex=[severDataDict.dataDict objectForKey:@"sex"];
                
                commdity.ProvinceName=[severDataDict.dataDict objectForKey:@"provinceName"];
                commdity.CityName=[severDataDict.dataDict objectForKey:@"cityName"];
                commdity.RegionName=[severDataDict.dataDict objectForKey:@"regionName"];
                if ([commdity.ProvinceName isEqualToString:@""]) {
                    commdity.ProvinceName=@".";
                }
                if ([commdity.CityName isEqualToString:@""]) {
                    commdity.CityName=@".";
                }
                if ([commdity.RegionName isEqualToString:@""]) {
                    commdity.RegionName=@".";
                }
                commdity.adress=[NSString stringWithFormat:@"%@%@%@%@",commdity.ProvinceName,commdity.CityName,commdity.RegionName,[severDataDict.dataDict objectForKey:@"address"]];
                
                [self.delegate secondViewController:self
                             updateText:commdity.memberId];
    NSLog(@"----%@", commdity.memberId);
    [self.navigationController popViewControllerAnimated:YES];
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:requestResultStr delegate:self cancelButtonTitle:@"确定返回" otherButtonTitles: nil];
                [alert show];
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];

    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex == 0) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    
}
-(void)loadStockVC
{
    
    if (![scanStockResultArray containsObject:stringValue]) {
        
        
        [self requestItemDetail:stringValue];//不一样的
        
    }else{
        
        
    }
}

//放到对应的数组
-(void)requestItemDetail:(NSString *)codeStr
{
    
    if (![scanStockResultArray containsObject:codeStr]) {
        NSLog(@"stringValue===%@",codeStr);
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"Token"];
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"Token"];
        [params setObject:codeStr forKey:@"ItemCode"];
        [HttpRequest requestData:@"Product/ItemDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    
                    [self setScanStockStringValue:stringValue urlStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"ImageUrl"] typeStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"ItypeName"] seriesStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"SeriesName"] dateStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"InDate"] weightStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"Gram"] priceStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"Price"] whereStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"WhsName"] itemNameStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"ItemName"] codeStr:[[severDataDict.dataDict objectForKey:@"DataItem"] objectForKey:@"ItemCode"]];
                    
                }else
                {
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
            }
            else
            {
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
    }
}
-(void)setScanStockStringValue:(NSString *)str urlStr:(NSString *)urlStr typeStr:(NSString *)typeStr seriesStr:(NSString *)seriesStr dateStr:(NSString *)dateStr
                     weightStr:(NSString *)weightStr priceStr:(NSString *)priceStr whereStr:(NSString *)whereStr itemNameStr:(NSString *)itemNameStr codeStr:(NSString *)codeStr
{
    if (![scanStockResultArray containsObject:str]) {
        
        [scanStockResultArray addObject:str];
        
        [itemWeightArray addObject:weightStr];
        [itemUrlArray addObject:urlStr];
        [itemPriceArray addObject:priceStr];
        [itemWhereArray addObject:whereStr];
        [itemNameArray addObject:itemNameStr];
        [itemCodeArray addObject:codeStr];
        commdity.how=@"123";
        [shuSCANSTOCK1 addTarget:self action:@selector(scanStockCountBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [shuSCANSTOCK1 setTitle: [NSString stringWithFormat:@"%d", [shuSCANSTOCK1.titleLabel.text intValue]+1] forState:UIControlStateNormal];
        
    }
}
-(void)loadShopVC
{
    commdity.noId=stringValue;
    [self.delegate secondViewController:self
                             updateText:stringValue];
    [self.navigationController popViewControllerAnimated:YES];
//    GetProductDetailViewController*detailViewController = [[GetProductDetailViewController alloc] init];
//    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
}
-(void)scanStockCountBtnClick
{
    [_captureSession stopRunning];
    
    _captureSession = nil;
    [timer invalidate];
    timer=nil;
    //    NSLog(@"－－－－－－%@",itemCodeArray);
    //    NSLog(@"－－－－－－%@",commdity.ItemCode44);
    //
    //    commdity.ItemCode44=itemCodeArray;
    //    commdity.ItemName44=itemNameArray;
    //    commdity.ImageUrl44=itemUrlArray;
    //    commdity.Gram44=itemWeightArray;
    //    commdity.Price44=itemPriceArray;
    //    commdity.WhsName44=itemWhereArray;
    //
    //    kucunViewController*detailViewController = [[kucunViewController alloc] init];
    //    [self.navigationController pushViewController:detailViewController animated:YES];
    
    //    if ([self.delegate respondsToSelector:@selector(scanHomeStockResult:_itemNameArray:_itemWhereArray:_itemPriceArray:_itemUrlArray:_itemWeightArray:_itemSeriesNameArray:_itemTypeNameArray:_itemInDateArray:)]) {
    //
    //        [self.delegate scanHomeStockResult:itemCodeArray _itemNameArray:itemNameArray _itemWhereArray:itemWhereArray _itemPriceArray:itemPriceArray _itemUrlArray:itemUrlArray _itemWeightArray:itemWeightArray _itemSeriesNameArray:itemSeriesNameArray _itemTypeNameArray:itemTypeNameArray _itemInDateArray:itemInDateArray];
    //    }
    
}




-(void)webVC
{
    
    
    
    
    
    
    
}



-(IBAction)backBtnClick:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
-(void)stopReading{
    [_captureSession stopRunning];
    _captureSession = nil;
    
    [_videoPreviewLayer removeFromSuperlayer];
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定哦 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:3.0f];
    
}


- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:5.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
